using System;
using System.Windows.Forms;
using MediaPortal.GUI.Library;
using MediaPortal.GUI.Video;
//using MediaPortal.Video.Database;
using MediaPortal.Util;
using MediaPortal.Dialogs;
using MediaPortal.Player;
using System.Data;
using System.ComponentModel;
using c3o.Framework.Web;
using System.Collections.Specialized;
using System.Xml;
using System.Xml.Serialization;
using System.IO;


namespace MediaPortal.GUI
{
	public class GUIDataTable : GUIVideoBaseWindow                                
	{
		[SkinControlAttribute(80)]		protected GUITextScrollUpControl detailbox = null;
		[SkinControlAttribute(24)]		protected GUIImage imgItem = null;

        protected string xmlSection = null;

		public DataTable Datasource;
		public void Databind()
		{
			GUIHelper.Databind(this.Datasource, this.facadeView);

			this.RefreshTitle();
		}

		protected override void OnPageLoad()
		{
			base.OnPageLoad();
			
			// Set Focus on List
			GUIControl.FocusControl(this.GetID, this.facadeView.GetID);
		}

		protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
		{
            base.OnClicked(controlId, control, actionType);

			if (control == this.facadeView) this.OnListView();			
		}

		virtual protected void OnDelete()
		{
		}

        public override void OnAction(Action action)
        {
            base.OnAction(action);

            switch (action.wID)
            {
                case Action.ActionType.ACTION_STOP:
                    this.OnStop();
                    break;
                case Action.ActionType.ACTION_PLAY:
                    this.OnPlay();
                    break;
            }

//            if (action.IsUserAction())
  //          {
    //           this.detailbox.Label = item.DVDLabel;
      //      }
        }



        //public override void OnAction(Action action)
        //{            
        //    if (action.wID == Action.ActionType.ACTION_PREVIOUS_MENU)
        //    {
        //        if (this.ListMode == "Sites")
        //        {
        //            base.OnAction(action);
        //        }
        //        else
        //        {
        //            this.ShowSites();
        //        }
        //    }
        //    else
        //    {
        //        base.OnAction(action);
        //    }


        //    switch (action.wID)
        //    {
        //        case Action.ActionType.ACTION_STOP:
        //            this.OnStop();
        //            break;
        //        case Action.ActionType.ACTION_PLAY:
        //            this.OnPlay();
        //            break;
        //    }

        //    if (action.IsUserAction())
        //    {
        //        if (this.CurrentSite != "UKNova")
        //        {
        //            GUIListItem item = this.facadeView.SelectedListItem;
        //            if (item != null)
        //            {
        //                if (this.ListMode == "Sites.List")
        //                {
        //                    this.detailbox.Label = item.DVDLabel;
        //                }
        //            }
        //        }
        //    }
        //}


		protected virtual void OnStop()
		{

		}

		protected virtual void OnPlay()
		{

		}

		public void RefreshTitle()
		{
			GUIListItem item = facadeView.SelectedListItem;

			if (item != null)
			{
				GUIPropertyManager.SetProperty("#selecteditem", item.Label);
				GUIWindowManager.Process();

				this.detailbox.Label = item.DVDLabel;
				//this.imgItem.FileName = item.IconImage;
			}

		}


		virtual protected void OnListView()
		{
			GUIListItem item = this.facadeView.SelectedListItem;

			if (item != null)
			{
			}
		}



		virtual protected void OnListViewList()
		{
		}


		//virtual protected void ShowSite()
		//{
		//    ListMode = "Sites.List";
		//    this.bttnDelete.Disabled = false;
		//    this.bttnDelete.Label = "Delete Feed";

		//    if (this.selectedOutline != null)
		//    {
		//        if (this.selectedOutline.url != null && this.selectedOutline.url.Length > 0)
		//        {
		//            this.ShowRSS();
		//        }
		//        else
		//        {
		//            this.ListMode = "Sites.Opml.List";
		//            this.SelectOutline(this.opmlList, this.selectedOutline, GUIFacadeControl.ViewMode.List);
		//        }
		//    }

		//    GUIControl.FocusControl(this.GetID, this.facadeView.GetID);
		//}
	


		



		





        //protected void DownloadAndCache(string imageUrl, string title)
        //{
        //    if (imageUrl.Length > 0)
        //    {
        //        string coverArtImage = MediaPortal.Util.Utils.GetCoverArtName(Thumbs.MovieTitle, title);
        //        string largeCoverArtImage = MediaPortal.Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, title);

        //        if (!System.IO.File.Exists(coverArtImage))
        //        {
        //            string imageExtension;
        //            imageExtension = System.IO.Path.GetExtension(imageUrl);
        //            if (imageExtension.Length > 0)
        //            {
        //                string temporaryFilename = "temp";
        //                temporaryFilename += imageExtension;
        //                MediaPortal.Util.Utils.FileDelete(temporaryFilename);

        //                MediaPortal.Util.Utils.DownLoadAndCacheImage(imageUrl, temporaryFilename);
        //                if (System.IO.File.Exists(temporaryFilename))
        //                {
        //                    MediaPortal.Util.Picture.CreateThumbnail(temporaryFilename, coverArtImage, 128, 128, 0);
        //                    MediaPortal.Util.Picture.CreateThumbnail(temporaryFilename, largeCoverArtImage, 512, 512, 0);
        //                }

        //                MediaPortal.Util.Utils.FileDelete(temporaryFilename);
        //            }
        //        }
        //    }
		//}



	}
}